Data Types

Format Table Column Data

Description
This example demonstrates how to customize the Data Access tier of your application so that the entire application uses a custom class to validate, format, and parse all values for a specific column in a Table. Specifically, this example demonstrates how to customize your application so that a column of a table only uses a custom display format to display them. The example uses very simple validation and formatting logic, but you can modify the sample code to implement your own business rules.
Variables
Table Name
Select a database table having currency column
Column Name
Select the name of the currency column that requires new display format
Applies to
DataAccessClass class
Code
 
' Customization for ${Table Name}Access class.
' A custom column class that has a special display format.
 Public Class MyCustomCurrencyColumn
    Inherits BaseClasses.Data.CurrencyColumn
    Public Sub New(ByVal col As BaseClasses.Data.CurrencyColumn)    
        MyBase.New(col.Number, col.InternalName, col.Name, col.TableDefinition, Nothing, Nothing, Nothing)        
        Me.IsIdentity = col.IsIdentity
        Me.DbDataType = col.DbDataType
        Me.DefaultValue = col.DefaultValue
        Me.DatabaseDefaultValue = col.DatabaseDefaultValue
        Me.DisplayFormat = col.DisplayFormat
        Me.DbFormat = col.DbFormat
        Me.IsRequired = col.IsRequired
        Me.IsIndexed = col.IsIndexed
        Me.IsUnique = col.IsUnique
        Me.IsValuesReadOnly = col.IsValuesReadOnly
        Me.IsValuesComputed = col.IsValuesComputed
        ' Me.Precision = col.Precision
        ' Me.Scale = col.Scale
        ' Me.SetConstraintString(col.GetConstraintString())        
    End Sub

    ' Overridden to put angle brackets around the display string.    
    Public Overloads Overrides Function ToDisplayString(ByVal value As ColumnValue, _
        ByVal format As String) As String        
        Return String.Format("<{0}>", MyBase.ToDisplayString(value, format))    
    End Function    
End Class

' Overridden to customize this object's TableDefinition's ColumnList.
Protected Overrides Sub Initialize()
    MyBase.Initialize()

    ' Construct a custom column instance using the current ${Column Name}.
    Dim newCol As New MyCustomCurrencyColumn(Me.${Column Name}Column)

    ' Replace the ${Column Name} with the custom column instance.
    Dim i As Integer 
    i = Me.TableDefinition.ColumnList.IndexOf(Me.${Column Name}Column)
    Me.TableDefinition.ColumnList.Item(i) = newCol    
End Sub
     

Terms of Service Privacy Statement